﻿@using Website.Models.Domain
@model Website.Models.ViewModels.ProfilesView
@{
    this.ViewBag.Title = "Opret Profil";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var errorMsg = new HtmlString(string.Empty);
    if (this.ViewData["ErrorMessage"] != null)
    {
        errorMsg = this.ViewData["ErrorMessage"] as HtmlString;
    }

}

<script>
    $(function() {
        $("#newLocation").click(function() {
            $("#dialog").dialog({
                width: "340px",
                modal: true
            });
        });
        $('#CreateLocationForm').submit(function(e) {
            e.preventDefault();
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function(result) {
                    if (result.success) {
                        // We have a JSON object in case of success
                        $('#Locations')
                            .append($("<option></option>")
                                .attr("value", result.locationID)
                                .text(result.locationName))
                            .val(result.locationID);


                        $("#dialog").dialog('close');
                    } else {
                        // We have the partial with errors in case of failure
                        // so all we have to do is update the DOM
                        $('#CreateLocationForm').html(result);
                    }
                }
            });
        });
    });
</script>

@using (this.Html.BeginForm())
{
    <div class="error">
        @errorMsg
    </div>

    <div class="formBullet">Navn*:</div>
    <div class="formEntry">
        <input type="text" name="Name" tabindex="1" autofocus="autofocus" /></div>

    <div class="formBullet">CVR:</div>
    <div class="formEntry">
        <input type="text" name="CVR" tabindex="2"  /></div>

    <div class="formBullet">Relation*:</div>
    <div class="formEntry">
        <select name="Relation"  tabindex="3" >
            <option value="@Guid.Empty">Vælg en relation</option>
            @foreach (ProfileRelation rel in this.Model.Relations.OrderBy(x => x.Type))
            {
                <option value="@rel.ID">@rel.Type</option>
            }
        </select>
    </div>

    <div class="formBullet">Kontakt type*:</div>
    <div class="formEntry">
        <select name="ContactType" tabindex="4" >
            <option value="@Guid.Empty">Vælg en kontakt-type</option>
            @foreach (ProfileContactType c in this.Model.ContactTypes.OrderBy(x => x.Type))
            {
                <option value="@c.ID">@c.Type</option>
            }
        </select>
    </div>

    <div class="formBullet">Sektor og type*:</div>
    <div class="formEntry">
        <select name="SubType" tabindex="5" >
            <option value="@Guid.Empty">Vælg en type</option>
            @foreach (ProfileSubtype typ in this.Model.Subtypes.OrderBy(x => x.Type.Sector.Name).ThenBy(x => x.Type.Name).ThenBy(x => x.Name))
            {
                <option value="@typ.ID">
                    @typ.Type.Sector.Name - 
                    @typ.Type.Name
                    @if (!typ.Name.Equals(string.Empty))
                    {
                        @Html.Label(string.Format(" - {0}", typ.Name))
                    }

                </option>
            }
        </select>
    </div>

    <div class="formBullet">Lokation*:</div>
    <div class="formEntry">
        <select name="Location" id="Locations" tabindex="6" >
            <option value="@Guid.Empty">Vælg en lokation</option>
            @foreach (Location loc in this.Model.Locations.OrderBy(x => x.Name))
            {
                <option value="@loc.ID">@loc.Name</option>
            }
        </select>
        <input type="button" value="Ny" id="newLocation" />
    </div>

    <div class="buttonHolder">
        <input type="submit" value="Opret" tabindex="7" /></div>
}




<div id="dialog" title="Opret ny lokation" style="display: none;">
    @Html.Partial("~/Views/Locations/_CreateLocationPartial.cshtml", new Location())
</div>